window.onload = function(){
    $("#btn").click(function(){
        var value = $("#input").val()
        // console.log(value);
        $("#box").html("")
        var url = `http://192.168.4.18:3000/search?keywords=${value}&type=10`
        ajax({
            url,
            method:"get",
            success:res=>{
                handleData(res,value)
            }
        })
    })

    function handleData(res,value){
        var arr = res.result.albums;
        // console.log(arr);
        var length = arr.length
        var search = `
            <p class="result">搜索"${value}",找到<span class="red">${length}</span>张专辑</p>
            <div class="container">
            </div>
        `
        $("#box").append(search)
        arr.forEach(item=>{
            var html = `
                <div>
                    <img src=${item.blurPicUrl}>
                    <a href="#" class="title">${item.name}</a>
                    <p class="name">${item.artist.name}</p>
                </div>
            `
            $(".container").append(html)
        })
    }
}